<?php

/**
 * 敏感词模型 
 */
class BadwordModel extends Model {

    public function checkBadword($content) {
        $badwords = $this->badwords();
        foreach ($badwords as $bv) {
            if (strpos(' '.$content, $bv)) {
                return reStatus(false, '敏感词' . $bv, $bv);
            }
        }
        return reStatus(true);
    }

    public function badwords() {
        $cacheID  = 'badwords';
        if (($badwords = F($cacheID)) === false) {
            $list = $this->where(array('status'  => 1))->select();
            $badwords = getSubByKey($list, 'value');
            S($cacheID, $badwords);
        }
        return $badwords;
    }

}

?>
